<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>

  <div id="app">
    <h1>{{initNum}}</h1>
    <!-- @countchange="handleChange"：事件的订阅 -->
    <button-counter :num='initNum' @abc="handleChange"></button-counter>
    <!-- <button-counter :num=123></button-counter>
    <button-counter num="345"></button-counter> -->
  </div>

  <script>

    //全局组件
    Vue.component('ButtonCounter', {
      props: ['num'],
      //每个组件数据的独立拷贝
      data() {
        return {
        }
      },
      template: `
      <div>
        <h1>{{num}}</h1>
        <button @click="increment()">加{{num}}</button>
      </div>
      `,
      methods: {
        increment() {
          this.num += 1;
          //事件的发布
          this.$emit('abc', this.num)
        }
      }
    })

    var vm = new Vue({
      el: "#app",
      data: {
        initNum: 100
      },
      methods: {
        handleChange(num) {
          this.initNum = num;
        }
      }
    })



  </script>

</body>

</html>